package cn.ncupyh;

public class Triangle {
//    --------------------------------
    private int a;
    private int b;
    private int c;

//    --------------------------------
    public Triangle(int a, int b, int c) {
        this.a = a;
        this.b = b;
        this.c = c;
    }

    public Triangle() {
    }

    public int getA() {
        return a;
    }

    public void setA(int a) {
        this.a = a;
    }

    public int getB() {
        return b;
    }

    public void setB(int b) {
        this.b = b;
    }

    public int getC() {
        return c;
    }

    public void setC(int c) {
        this.c = c;
    }

    //判断是否符合三角形定则
    boolean isRightTriangle(int a,int b,int c){
        int max = a;
        int min = c;
        int mid;
        if(max < b ){
            max = b;
        }
        if(max < c){
            max = c;
        }
        if(min > b ){
            min = b;
        }
        if(min > c){
            min = c;
        }
        mid = a + b + c - max - min;
        //判断是否符合三角形定则
        if((min + mid)>max && (max - mid)<min){
                return true;
        }
        return false;
    }

    //判断是否是等腰三角形
    boolean idLsoscelesTriangle(int a,int b,int c){
        //求出最大值,最小值和中间值
        int max = a;
        int min = c;
        int mid;
        if(max < b ){
            max = b;
        }
        if(max < c){
            max = c;
        }
        if(min > b ){
            min = b;
        }
        if(min > c){
            min = c;
        }
        mid = a + b + c - max - min;
        //判断是否是等腰三角形
        if((min + mid)>max && (max - mid)<min){
            if(min == mid){
                return true;
            }
            return false;
        }
        return false;
    }

    //判断是否是等边三角形
    boolean isEquilateralTriangle(){
        boolean i = isRightTriangle(a,b,c);
        if(i){
            //判断等边三角形
            if(b == a && a == c){
                System.out.println("三边可以构成等边三角形!");
                return true;
            }
            System.out.println("三边不可以构成等边三角形!");
            return false;
        }
        return false;
    }

    //用海伦公式求面积
//    海伦公式：s=sqrt(p*(p-a)(p-b)(p-c))
//假设在平面内，有一个三角形，边长分别为a、b、c，三角形的面积S可由以下公式求得：s=sqrt(p*(p-a)(p-b)(p-c))
//而公式里的p为半周长（周长的一半）：p=1/2(a+b+c)
    double getArea(int a,int b,int c){
        boolean i = isRightTriangle(a,b,c);
        if( i ){
             float p = (1/2)*(a+b+c);//半周长
             double s = Math.sqrt(p*(p-a)*(p-b)*(p-c));//面积
             System.out.println("三角形的面积为:" + s);
             return s;
        }
            return -1;
    }

//求周长
    double getLength(int a,int b,int c){
       boolean i = isRightTriangle(a,b,c);
       if(i){
           double length = a + b + c;
           System.out.println("周长为:" + length);
           return length;
       }
       return -1;
    }

    public static void main(String[] args) {
        Triangle t = new Triangle(3,4,5);
        boolean i = t.isRightTriangle(1,2,3);
        if(i){
            System.out.println("是三角形!");
        }
        else{
            System.out.println("不是三角形!");
        }
    }


}


